package org.example.spring.mapper;

import org.apache.ibatis.annotations.*;
import org.example.spring.domain.pojo.Cart;

import java.util.ArrayList;

@Mapper
public interface CartMapper {

    @Select("SELECT quantity FROM cart WHERE flower_id = #{flowerId}")
    Integer getFlowerCount(Integer flowerId);

    @Insert("INSERT INTO cart (user_id, flower_id, quantity) VALUES (#{userId}, #{flowerId}, #{quantity})")
    void addCart(Cart cart);
    @Update("UPDATE cart SET quantity = #{quantity} WHERE user_id = #{userId} AND flower_id = #{flowerId}")
    void updateCart(Cart cart);

    @Select("SELECT * FROM cart WHERE user_id = #{userId} order by cart_item_id")
    ArrayList<Cart> getCartListByUserId(int userId);

    @Delete("DELETE FROM cart WHERE flower_id = #{flowerId} AND user_id = #{userId}")
    void deleteCart(Integer flowerId, Integer userId);
}
